package com.noble.glamour.module.logic.config;

import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.bean.center.user.light.UserInfoLightweightList;
import com.noble.glamour.bean.center.user.light.UserLightList;
import com.noble.glamour.bean.center.user.others.UserBlack;
import com.noble.glamour.bean.config.CommonConfig;
import com.noble.glamour.bean.config.VideoVerifyBean;
import com.noble.glamour.bean.file.UpLoadResult;
import com.noble.glamour.bean.my.ChatInfo;
import com.noble.glamour.bean.my.GiftMessageList;
import com.noble.glamour.bean.my.RedOneKeyList;
import com.noble.glamour.bean.my.RedbagList;
import com.noble.library.base.bean.BaseData;
import com.noble.glamour.bean.settting.ContactBean;
import com.noble.glamour.bean.settting.Setting;
import com.noble.glamour.bean.start.LoginResult;
import com.noble.glamour.bean.start.OfflineMsg;
import com.noble.library.host.Hosts;
import com.noble.library.third.ThirdConstant;
import com.noble.glamour.ui.agora.act.bean.Accept;
import com.noble.glamour.ui.agora.act.bean.ChatStatus;
import com.noble.glamour.ui.agora.act.bean.Invited;
import com.noble.glamour.ui.agora.act.bean.RtcComment;
import com.noble.glamour.ui.agora.act.bean.RtcComplainReasons;
import com.noble.glamour.ui.agora.act.bean.RtcGiftList;
import com.noble.glamour.ui.agora.act.bean.RtcProps;
import com.noble.glamour.ui.user.check.bean.VideoConfig;
import com.noble.glamour.ui.user.check.bean.VideoSetting;
import com.noble.glamour.ui.user.paygoods.bean.PayGoods;

import java.util.Map;

/**
 * 管理常用的Url参数信息
 */
public enum UrlParam {
    // ========================= utils工具接口 ==============
    reqSendCode(Hosts.FATE_IT_GO, "v1/utils/send_code", null, false),               // 获取验证码
    uploadFile(Hosts.FATE_IT_OSS, "v1/utils/upload", UpLoadResult.class, false),    // 上传文件

    // ========================= user_login ==============
    reqVerifyCode(Hosts.FATE_IT_GO, "v1/user_login/login/mobile", LoginResult.class, false),  // 手机号验证码登录
    weChatLogin(Hosts.FATE_IT_GO, "v1/user_login/login/wechat", LoginResult.class, false),    // 微信登录
    getWXAccessToken(ThirdConstant.WECHAT_API_SERVER, "oauth2/access_token", null, false),    // 获取微信AccessToken
    getWXUserInfo(ThirdConstant.WECHAT_API_SERVER, "userinfo", null, false),                  // 获取微信用户资料

    // ========================= user_info ==============
    reqMyInfo(Hosts.FATE_IT_GO, "v1/user_info/get_detail", UserDetail.class, true),      // 获取个人资料
    reqOtherInfo(Hosts.FATE_IT_GO, "v1/user_info/get_detail_other", UserDetail.class, true),// 获取他人资料
    reqUserInfoSummary(Hosts.FATE_IT_GO, "v1/user_info/get_simple_batch", UserLightList.class, true),  // 批量获取轻量级的用户信息
    reqModifyInfo(Hosts.FATE_IT_GO, "v1/user_base/update", null, true),    // 修改用户个人信息
    uploadPhoto(Hosts.FATE_IT_GO, "v1/rec_user_photo/add", null, true),         // 上传相册
    deletePhoto(Hosts.FATE_IT_GO, "v1/rec_user_photo/delete", null, true),      // 删除照片

    // 女性：上传视频
    uploadVideo(Hosts.FATE_IT_GO, "v1/rec_user_video/add", null, true),         // 用户上传视频
    deleteVideo(Hosts.FATE_IT_GO, "v1/rec_user_video/delete", null, true),      // 删除视频

    // ========================= user_recommend ==============
    reqRecommednList(Hosts.FATE_IT_GO, "v1/user_recommend/get", UserLightList.class, true), // 获取推荐列表

    // ========================= message =====================
    sendMessage(Hosts.FATE_IT_MSG, "v1/send_msg/yy_chat", null, true),      // 发送消息走Http短连接


    /**
     * 以下为周隆提供接口: 暂时保留
     */
    // ====================== 初始化设置相关 =================
    staticConfig(Hosts.FATE_IT_GO, "i/common/GetConfig", CommonConfig.class, false),  //获取服务器静态配置
    // ====================== 注册相关 =================
    reqBindMobile(Hosts.FATE_IT_GO, "index/userinfo/BindMobile", null, true),           // 绑定手机
    // ====================== 用户信息相关 =================

    // ====================== 消息相关 =================
    reqChatInfo(Hosts.FATE_IT_GO, "index/userinfo/ChatInfo", ChatInfo.class, true),       // 聊天窗口信息
    reqOfflineMsg(Hosts.FATE_IT_GO, "index/message/OfflineMsgs", OfflineMsg.class, true), // 离线消息
    sendGift(Hosts.FATE_IT_GO, "index/gift/SendGift", null, true),                       // 发送礼物

    //============ 支付 暂未完成=============
    reqCommodityList("user/payListNode", PayGoods.class),               // 商品列表
    reqWX(Hosts.FATE_IT_PROTOCOL, "user/wxAllPayencry", null, true),    //微信支付
    reqAlipay(Hosts.FATE_IT_PROTOCOL, "user/alipayencry", null, true),  //银联支付


    // ===================== 音视频相关 start =========================
    // ----------------- 已替换 ----------------
    reqInviteChat(Hosts.FATE_IT_GO, "index/message/InviteVideoChat", Invited.class, true),      // 邀请对方
    reqAcceptChat(Hosts.FATE_IT_GO, "index/message/AcceptVideoChat", Accept.class, true), // 接受通信邀请
    reqRejectChat(Hosts.FATE_IT_GO, "index/message/RejectVideoChat", null, true),// 拒绝通信邀请
    reqStopChat(Hosts.FATE_IT_GO, "index/message/StopVideoChat", null, true),// 挂断聊天
    reqCheckChat(Hosts.FATE_IT_GO, "index/message/CheckVideoChat", ChatStatus.class, true),// 聊天中，客户端刷新聊天状态（轮询接口）
    reqCheckPornography(Hosts.FATE_IT_GO, "index/message/CheckPornography", null, true), // 视频聊天鉴黄接口
    reqTimeoutChat(Hosts.FATE_IT_GO, "index/message/SetTimeoutVideoChat", null, true),// 60s超时挂断请求接口
    girlSingleInviteVa(Hosts.FATE_IT_GO, "index/message/InviteVideoChatW", Invited.class, true),//女性单邀音视频


    // -------------- 暂时未替换 -------------
    joinGuild("user/addGroup", null, true),  //加入公会
    // 音视频聊天
    reqVideoChatConfig(Hosts.FATE_IT_GO, "xs/message/GetVideochatConfig", VideoConfig.class, true), // 获取他人音视频开关配置
    reqPushVideochatControl(Hosts.FATE_IT_GO, "xs/message/PushVideochatControl", null, true),// 男性，摄像头开关状态

    // 女性版：单邀，群邀
    reqVCGroupCancel(Hosts.FATE_IT_GO, "xs/message/VCGroupCancel", null, true),// 群发邀请： 取消群发邀请状态
    girlGroupInviteVa(Hosts.FATE_IT_GO, "xs/message/VCGroupInvite", null, true),  //女性群邀音视频
    reqGirlAcceptChat(Hosts.FATE_IT_GO, "xs/message/VCGroupAccept", Accept.class, false),   // 接受女性通信邀请

    // 音视频优化版
    reqGiftBanner(Hosts.FATE_IT_GO, "xs/gift/GiftBanner", RtcGiftList.class, false),
    reqGetFeedbackInfo(Hosts.FATE_IT_GO, "xs/message/GetFeedbackInfo", RtcComment.class, true),
    reqGetSettlement(Hosts.FATE_IT_GO, "xs/message/GetSettlement", RtcComment.class, true),
    reqAddFeedback(Hosts.FATE_IT_GO, "xs/message/AddFeedback", null, true),
    reqAddComplaint(Hosts.FATE_IT_GO, "xs/message/AddComplaint", null, true),
    reqGetPropList(Hosts.FATE_IT_GO, "xs/message/GetPropList", RtcProps.class, true),
    reqUsingProp(Hosts.FATE_IT_GO, "xs/message/UsingProp", null, true),
    reqGetComplainReasons(Hosts.FATE_IT_GO, "xs/message/GetComplainReasons", RtcComplainReasons.class, true),
    // ===================== 音视频相关 end =========================


    // ======================= 暂时使用着的接口 =====================================
    reqLogin(Hosts.FATE_IT_GO, "base/userinfo/UserLogin", LoginResult.class, false), //  登录接口
    userVerify("User/Verify", true),    // 用户身份认证提交


    // ================================================== 缘分吧无用接口 ===================================
    checkUpdate("public/checkupNew", null, true),   //检查软件升级
    activeStatistic("Behav/act", true), //php旧版用户应用激活统计
    userOnline("user/userOnline", true),//php旧版用户应用内行为统计
    payStatistic("user/ppc", true),     //php旧版用户充值统计
    statistics(Hosts.FATE_IT_GO, "x/hdp/Action2", null, false),//大数据统计
    locationStatistics(Hosts.FATE_IT_GO, "xs/location/UpdateUserPosition", null, false),//位置信息统计
    forgotPassword("Public/forgotPassword"),//找回密码
    reqForgotsms("Public/forgotsms", false),//找回密码发送验证码
    getserviceqq("user/getserviceqq", ContactBean.class, true),//获取客服信息
    //================================ 配置项 ==================================
    CMDRequest(""),//cmd请求中默认拼接内容为空，通过resetHost方式进行使用
    reqSayHiList("pubtest/getSayHiUserNew", UserInfoLightweightList.class, true),//一键打招呼列表
    reqOfflineRecvedMsg(Hosts.FATE_IT_GO, "xs/message/OfflineRecved", null, true), // 离线送达消息

    modifyPassword("user/modifyPassword", null, true),//修改密码
    feedBack("user/feedback"),//意见反馈
    getSetting("s/uinfo/GetSetting", Setting.class, true),//获取设置信息
    updateSetting("s/uinfo/UpdateSetting", true),//设置信息修改
    //获取自己的音频、视频开关配置
    reqMyVideochatConfig(Hosts.FATE_IT_GO, "xs/message/MyVideochatConfig2", VideoVerifyBean.class, true),
    //音视频开关修改
    setVideochatConfig(Hosts.FATE_IT_GO, "xs/message/SetVideochatConfig", null, true),
    //上传视频认证配置
    addVideoVerify(Hosts.FATE_IT_GO, "xs/message/AddVideoVerify", null, true),

    // 获取用户验证信息(密)
    getVerifyStatus("User/getVerifyStatus", true),

    //============================== 用户资料相关接口 =============================
    reqSetInfo("i/uinfo/SecSetInfo", true),                   // 用户设置更新
    reqIsBlack(Hosts.FATE_IT_GO, "xs/userrelation/IsMyBlack", UserBlack.class, true), // 查询某用户是否处于黑名单中
    reqAddBlack(Hosts.FATE_IT_GO, "xs/userrelation/AddBlack", null, true),          // 拉黑某用户
    reqRemoveBlack(Hosts.FATE_IT_GO, "xs/userrelation/RemoveBlack", null, true),    // 拉黑列表移除某用户
    reqSetRemarkName(Hosts.FATE_IT_GO, "xs/userrelation/SetRemakName", null, true),             // 设置用户备注名
    reqGetOpposingVideoSetting(Hosts.FATE_IT_GO, "xs/userrelation/GetOpposingVideoSetting", VideoSetting.class, true), // 获取接受他人音视频配置
    reqSetOpposingVideoSetting(Hosts.FATE_IT_GO, "xs/userrelation/SetOpposingVideoSetting", null, true), // 设置接受他人音视频配置

    // 私密视频相关
    reqSetPopnum("video2/setPopnum"),        // 增加私密视频人气值
    reqSetViewTime("video2/setviewtime"),    // 设置私密视频观看次数
    reqUnlockVideo("video2/unlockvideo"),    // 解锁视频

    //获取昵称和头像的最近变更 list
    reqBasicUserInfoMsg("s/uinfo/NickChangedList", UserInfoLightweightList.class, true),

    // 上传头像
    uploadAvatar(Hosts.FATE_IT_HTTP_PIC, "index/uploadAvatar", null, false),


    //============================== 用户资料模块相关接口 =============================
    //摇钱树红包列表
    reqTreeRedbagList("fruit/redbaglisttree", RedbagList.class, true),
    reqRedbagList("fruit/redbaglist", RedbagList.class, true),
    //客户端用户红包入袋fruit/addredonekey
    reqAddredTotal("fruit/addredtotalnew", false),
    // 红包记录--红包入袋 -- 一键入袋(24不能提现)
    reqAddredonekey("fruit/addredonekey", RedOneKeyList.class, true),
    // 客户端请求用户提现列表
    reqWithdrawlist("fruit/withdrawlistNew", true),
    // 红包记录--提现申请
    reqWithdraw("fruit/withdrawNew", true),
    // 红包记录--提现申请获取地址
    reqWithdrawAddress("fruit/withdrawaddressNew", true),
    // 红包记录--提现申请修改地址
    reqWithdrawModify("fruit/withdrawmodifyNew", true),
    // 获取礼物列表
    getGiftLists("gift/getGifts", true),
    // 索要礼物
    begGift("gift/begGift", true),
    //接收礼物
    receiveGift("gift/receiveGift", null, true),
    // 手机验证
    sendSMS("public/sendSMS", true),
    // 索要礼物群发
    qunFa(Hosts.FATE_IT_GO, "xs/discovery/Qunfa", null, true),
    // 私密视频/图片/聊天的解锁通知 （此接口不包含送礼逻辑，只有计数统计等作用。等于解锁送礼时，调用完送礼接口OK，再调用此接口）
    serectUnlock(Hosts.FATE_IT_GO, "xs/discovery/SerectUnlock", null, true),
    //女用户群发累计发送的用户数
    qunCount(Hosts.FATE_IT_GO, "xs/discovery/QunCount", null, true),
    // 我关注的列表
    getFollowing("MoneyTree/getFollowing", true),
    // 关注我的列表
    getFollowers("MoneyTree/getFollowers", true),
    // 上传身份证照片
    uploadIdCard("User/uploadIdCard", true),
    // 获取最近礼物列表
    lastGiftList("gift/lastgiftlist", GiftMessageList.class, false),

    //================= 发现 ===========
    //举报
    complainBlack(Hosts.FATE_IT_GO, "xs/userrelation/ComplainBlack", null, true),
    //获取我的好友列表
    getMyFriends(Hosts.FATE_IT_GO, "xs/userrelation/GiftFriends", UserInfoLightweightList.class, true),
    //新版 获取我的好友列表，应服务器要求暂时废弃2017/7/17

    //视频好友
    getVideoFriends(Hosts.FATE_IT_GO, "xs/userrelation/VideoFriends", UserInfoLightweightList.class, true),

    //解锁好友
    getUnlockFriends(Hosts.FATE_IT_GO, "xs/userrelation/UnlockFriends", UserInfoLightweightList.class, true),

    @Deprecated
    getNewMyFriends(Hosts.FATE_IT_GO, "xs/userrelation/GetFriendsList", UserInfoLightweightList.class, true),
    //获取黑名单列表
    getMyDefriends(Hosts.FATE_IT_GO, "xs/userrelation/BlackList", UserInfoLightweightList.class, true),

    getVideoChatUsers(Hosts.FATE_IT_GO, "xs/discovery/VideochatUsers", UserInfoLightweightList.class, true), // 获取首页语聊推荐用户

    reqPhoneCard(Hosts.FATE_IT_CUP_HTTP, "user/card", null, true),  //手机卡

    reqSearchPhoneCard(Hosts.FATE_IT_CUP_HTTP, "user/checkSZPay", null, true),  //手机卡查询

    reqAliWapPay(Hosts.FATE_IT_CUP_HTTP, "user/aliWapPay", null, true),   //支付宝wap充值

    reqCustomFace(Hosts.FATE_IT_GO, "xs/message/GetCustomFace", null, true),   //获取自定义表情列表

    delCustomFace(Hosts.FATE_IT_GO, "xs/message/DelCustomFace", null, true),   //删除自定义表情

    addCustomFace(Hosts.FATE_IT_GO, "xs/message/AddCustomFace", null, true),   //添加自定义表情

    getUserNetInfo(Hosts.FATE_IT_GO, "xs/userinfo/GetUserNetInfo", null, true),  //获取用户设备网络信息

    updateNetInfo(Hosts.FATE_IT_GO, "xs/userinfo/UpdateNetInfo", null, true),  //设置用户设备网络信息

    refPayComplete(Hosts.FATE_IT_GO, "xs/userinfo/RefPayComplete", null, true), //刷新充值是否成功

    reqSerectComment(Hosts.FATE_IT_GO, "xs/discovery/SerectComment", null, true),  //私密视频/图片的评价

    reqQunGiftIds(Hosts.FATE_IT_GO, "xs/discovery/QunGiftIds", null, true),  //索要礼物的礼物列表

    reqQunPhotos(Hosts.FATE_IT_GO, "xs/discovery/QunPhotos", null, true),  //女用户群发私密照片索要礼物

    reqQunVideo(Hosts.FATE_IT_GO, "xs/discovery/QunVideo", null, true),  //女用户群发私密视频索要礼物

    reqSerectUnlock(Hosts.FATE_IT_GO, "xs/discovery/SerectUnlock", null, true),  //私密视频/语音/图片/聊天的解锁通知

    // 最后一个，占位
    LastUrlParam("");

    // -------------------------------内部处理逻辑----------------------------------------

    private String host = Hosts.HOST_URL;    //请求host
    private String spliceUrl = null;            //接口url，与host拼接得到完整url
    private boolean needLogin = false;          //请求是否需要登录才会发送
    private Class<? extends BaseData> parseClass = null;//请求返回体解析类

    // --------------构造方法 start--------------

    /**
     * host+接口url+解析bean
     */
    UrlParam(final String host, final String spliceUrl, final Class<? extends BaseData> parseClass, final boolean needLogin) {
        this.host = host;
        this.spliceUrl = spliceUrl;
        this.parseClass = parseClass;
        this.needLogin = needLogin;
    }

    /**
     * 接口url+解析bean+是否需要登录
     */
    UrlParam(final String spliceUrl, final Class<? extends BaseData> parseClass, final boolean needLogin) {
        this(Hosts.HOST_URL, spliceUrl, parseClass, needLogin);
    }

    /**
     * 接口url+解析bean
     */
    UrlParam(final String spliceUrl, final Class<? extends BaseData> parseClass) {
        this(spliceUrl, parseClass, false);
    }

    /**
     * 接口url+是否需要登录
     */
    UrlParam(final String spliceUrl, final boolean needLogin) {
        this(spliceUrl, null, needLogin);
    }

    /**
     * 接口url
     */
    UrlParam(final String spliceUrl) {
        this(spliceUrl, null);
    }

    // --------------构造方法 end--------------

    /**
     * 重设请求host
     *
     * @param host host地址
     * @return UrlParam
     */
    public UrlParam resetHost(String host) {
        this.host = host;
        return this;
    }

    /**
     * 重设接口url，特殊情况使用
     *
     * @param spliceUrl 接口url
     */
    public void resetSpliceUrl(String spliceUrl) {
        this.spliceUrl = spliceUrl;
    }

    /**
     * 是否需要登录才能发送的请求
     *
     * @return boolean值
     */
    public boolean isNeedLogin() {
        return needLogin;
    }

    /**
     * 获取完整Url
     *
     * @return url
     */
    public String getFinalUrl() {
        if (host.equals(Hosts.NO_HOST)) {
            return spliceUrl;
        }
        return host + spliceUrl;
    }

    /**
     * 获取一个实现了BaseData接口的实例
     *
     * @return 有Class的newInstance生成的实例
     */
    public BaseData getBaseData() {
        BaseData baseData = null;
        try {
            if (parseClass != null) baseData = parseClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baseData;
    }

    /**
     * 获取完整拼接参数的Url，用于缓存url等
     *
     * @param param 需要传送的参数
     * @return spliceUrl
     */
    public String getEntireUrl(Map<String, Object> param) {
        String url = this.spliceUrl;
        if (param != null) {
            for (Object o : param.entrySet()) {
                Map.Entry entry = (Map.Entry) o;
                Object key = entry.getKey();
                Object val = entry.getValue();
                url = url.replaceAll("\\{" + key.toString() + "\\}", val.toString());
            }
        }
        if (!host.equals(Hosts.NO_HOST)) {
            url = host + url;
        }
        return url;
    }
}